package com.yiqiu.common.mybatisplus.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.yiqiu.common.mybatisplus.handler.MyMetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author weiyi
 */
@Configuration
public class MybatisPlusConfig {

    /**
     * 自动填充字段处理器
     * @return 自定义
     */
    @Bean
    public MetaObjectHandler metaObjectHandler() {
        return new MyMetaObjectHandler();
    }

//    @Bean
//    public IKeyGenerator keyGenerator() {
//        return new H2KeyGenerator();
//    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页插件
        interceptor.addInnerInterceptor(getPaginationInnerInterceptor());
        //非法SQL阻断插件
        interceptor.addInnerInterceptor(getIllegalSqlInnerInterceptor());
        //防全表更新与删除插件
        interceptor.addInnerInterceptor(getBlockAttackInnerInterceptor());
        return interceptor;
    }

    public PaginationInnerInterceptor getPaginationInnerInterceptor() {
        return new PaginationInnerInterceptor();
    }
    public IllegalSQLInnerInterceptor getIllegalSqlInnerInterceptor() {
        return new IllegalSQLInnerInterceptor();
    }
    public BlockAttackInnerInterceptor getBlockAttackInnerInterceptor(){
        return new BlockAttackInnerInterceptor();
    }

}
